<?php
require_once  __DIR__ . '/includes/authenticate.php';
include_once './db_bb_connect.php';

$username = $_SESSION['username'];

$sql = "SELECT username, firstname, lastname 
FROM users
WHERE users.username = '$username'";

$result = $db->query($sql);
$row = $result->fetch_assoc();

$firstname = $row['firstname'];
$lastname = $row['lastname'];
$username = $row['username'];

?>

<h2>Settings</h2>

<br>
<div class="container-fluid">
	<div class="row"> 
	<div class="col-md-2"></div>
		<div class="col-md-2">
			<h3>Account Info </h3> <br/>
			<strong>Name: </strong> <?= $firstname;?>	<?= $lastname;?> <br/><br/>
			<strong> Username: </strong> <?= $username;?>	    <br/><br/>
			<button id="chpwbutton" class="btn btn-default">Change Password</button><br/>
		</div>
		<div class="col-md-6" id="settingssubcontent"></div>
		<div class="col-md-2"></div>
	</div>

</div>

<script type="text/javascript">

$("#chpwbutton").on("click", function(e) {
		$.ajax({
 			type: "GET",
  			url: "./changepw.php",
  			success: function(data) { 				
  				$("#settingssubcontent").html(data);
  			},
  			error: function (xhr, status, error) {
  				$("#settingssubcontent").html(xhr.responseText);
  			}
  		}); 
		e.preventDefault();
});

</script>